package com.wuye.controller;

import com.wuye.model.Menu;
import com.wuye.model.MenuDetail;
import com.wuye.model.Menus;
import com.wuye.service.MenuService;
import com.wuye.web.AppConfig;
import com.wuye.web.MenuType;
import com.wuye.web.ST;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import org.apache.commons.logging.*;

/**
 * Created by jiawenlong on 2016/6/8.
 */
@RestController
@RequestMapping("/menu")
public class MenuController {
	private Log log = LogFactory.getLog(this.getClass());
    @Autowired
    private MenuService menuService;
    @RequestMapping("/menus.jspx")
    @ResponseBody
    public String menuList(){
        JSONObject json = new JSONObject();
        List<Menus> lists = new ArrayList<Menus>();
        for(MenuType menuType:MenuType.values()){
            List<Object[]> menu = menuService.queryAllsByItemType(menuType.toString());
            List<MenuDetail> menus = menuService.convertList(menu);
            log.info(menus);
            String ss = menuType.getMenuType().toString();
            Menus mm = new Menus(menuType.toString(),menus,ss);
            lists.add(mm);
        }
        json.put("mylist",lists);
        json.put("times", AppConfig.pageTime);
        return json.toString();
    }
    @RequestMapping("/menusTime.jspx")
    @ResponseBody
    public String menuTime(){
        JSONObject json = menuService.orderTimes();
        String s1 =(String) json.get("s1");
        s1 = s1.substring(0,5);
        String s2 =(String) json.get("s2");
        s2 = s2.substring(0,5);
        return ST.ok.getJsonObject().put("s1",s1).put("s2",s2).toString();
    }
}
